package com.demo.rabbitmq.ack;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author sc
 * Created on  2018/9/16
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setVirtualHost("/");
        cf.setHost("localhost");
        cf.setPort(5672);
        cf.setNetworkRecoveryInterval(3000);
        cf.setAutomaticRecoveryEnabled(true);

        Connection connection = cf.newConnection();
        Channel channel = connection.createChannel();

        String exchange = "ack_ex";
        String routingKey = "ack.save";

        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder().expiration("10s").build();

        channel.basicPublish(exchange,routingKey,properties,"hello mq ack".getBytes());

        Thread.sleep(10000000);
    }
}
